package uk.ac.lkl.common.ui;



import java.awt.*;
import java.util.*;


/**
 * A layout that allows allocation of components to locations.
 * 
 * 
 * 
 * @author Darren Pearce
 * @version $Revision: 356 $
 * @version $Date: 2007-10-30 16:03:32 +0000 (Tue, 30 Oct 2007) $
 * 
 */
public class TableLayout { // implements LayoutManager2 {

    private ArrayList<ArrayList<Component>> componentMap;

    private int numRows;

    private int numColumns;


    public void addLayoutComponent(String name, Component component) {

    }


    public void removeLayoutComponent(Component component) {

    }


    public Dimension minimumLayoutSize(Container parent) {
        // could cache this...
        ArrayList<Integer> maximumRowHeights = new ArrayList<Integer>();
        ArrayList<Integer> maximumColumnWidths = new ArrayList<Integer>();

        for (int i = 0; i < numRows; i++)
            maximumRowHeights.add(0);

        for (int i = 0; i < numColumns; i++)
            maximumColumnWidths.add(0);

        for (int rowIndex = 0; rowIndex < componentMap.size(); rowIndex++) {
            ArrayList<Component> row = componentMap.get(rowIndex);
            for (int columnIndex = 0; columnIndex < row.size(); columnIndex++) {
                Component component = row.get(columnIndex);
                Dimension size = component.getSize();
                int width = size.width;
                int height = size.height;
                if (width > maximumColumnWidths.get(columnIndex))
                    maximumColumnWidths.set(columnIndex, width);

                if (height > maximumRowHeights.get(rowIndex))
                    maximumRowHeights.set(rowIndex, height);
            }
        }

        int totalRowHeight = 0;
        for (int maximumRowHeight : maximumRowHeights)
            totalRowHeight += maximumRowHeight;

        int totalColumnWidth = 0;
        for (int maximumColumnWidth : maximumColumnWidths)
            totalColumnWidth += maximumColumnWidth;

        return new Dimension(totalColumnWidth, totalRowHeight);
    }
}
